
 var cardid = '1004147982';
    var view_const_dish_SPECIAL_PRICE_YES = '2';
    var view_const_dish_SPECIAL_PRICE_VIP = '3';
    var view_const_dish_HOT_YES = '2';

    function setHeight(){
        var  cHeight;
        cHeight = document.documentElement.clientHeight;
        cHeight = (cHeight-55) +"px"
        document.getElementById("navBar").style.height =  cHeight;
        document.getElementById("infoSection").style.height =  cHeight;
    }

    //ajax处理
    //配合_doAjax方法使用
    function doSelect(){
        var dds = _qAll('#navBar dd');
        var aa=0, bb;
        var article = _q("#infoSection article");
        _forEach(dds, function(ele, idx, dds) {
            dds[idx].onclick = function(){
                _q('.active').className = null;
                this.className = "active";

                var div = document.getElementById("pInfo");
                div.innerHTML = '';

               $.ajax({
                    type: "GET",
                    url: "/zxims/f/wechat/diancan/getFoodByCategoryId",
                    data: {"bookCategory.id":this.getAttribute('categoryId')},
                    dataType: "json",
                    success: function(data){
                                $('#pInfo').empty();   //清空resText里面的所有内容
                                var html = ''; 
                                $.each(data, function(commentIndex, comment){
                                	if(typeof(comment.count) == "undefined"||comment.count==0){
                                		html += '<dl  style="clear:both;" >'+
                                		' <dt style="float:left; width:35%; padding:8% 3% "> <a href="/zxims/f/wechat/diancan/getFood/'+comment.id+'" class="dataIn"><img src="'+comment.img+'" alt="" title="" width="103px" height="75px"></a> </dt>'+
                                		'  <dt style="float:left; width:55%;	margin:3% 0 0 3%;">'+
                                		'  <p> <h3>'+comment.name+'</h3></p>'+
                                		'<p><font color="#a31410" style=" font-size:14px"><b>￥'+comment.price+'元/份</b></font></p>'+
                                		'   </dt> ' +
                                		'  <dd class="btn"> ' +
                                		'    <button style="display: none;"  id="minus_'+comment.id+'"  onclick="minus('+comment.id+')"  class="minus"><strong></strong></button> ' +
                                		'    <i style="display: none;"  id="count_'+comment.id+'"   >0</i> ' +
                                		'   <button class="add"   onclick="add('+comment.id+')"   ><strong></strong></button> ' +
                                		'   </dd> ' +
                                		'    </dl> ' ;
                                	}else{
                                		html += '<dl  style="clear:both;">'+
                                		' <dt style="float:left; width:35%; padding:8% 3% "> <a href="/zxims/f/wechat/diancan/getFood/'+comment.id+'" class="dataIn"><img src="'+comment.img+'" alt="" title="" width="103px" height="75px"></a> </dt>'+
                                		'  <dt style="float:left; width:55%;	margin:3% 0 0 3%;">'+
                                		'  <p> <h3>'+comment.name+'</h3></p>'+
                                		'<p><font color="#a31410" style=" font-size:14px"><b>￥'+comment.price+'元/份</b></font></p>'+
                                		'   </dt> ' +
                                		'  <dd class="btn"> ' +
                                		'    <button style="display:  inline-block;"  id="minus_'+comment.id+'"  onclick="minus('+comment.id+')"  class="minus"><strong></strong></button> ' +
                                		'    <i style="display:  inline-block;"  id="count_'+comment.id+'"   >'+comment.count+'</i> ' +
                                		'   <button class="add"   onclick="add('+comment.id+')"   ><strong></strong></button> ' +
                                		'   </dd> ' +
                                		'    </dl> ' ;
                                	}
                                });
                                $('#pInfo').html(html);
                             }
                });
            }
        });
    }


    //选择菜品按钮样式
    function doSelectBtn(){
        var btn = _qAll("article dl .btn");
        var btnIndex = 0,btnLength = btn.length;

        // countDish();
        for(btnIndex;btnIndex<btnLength;btnIndex++){

            var countNumText=parseInt(btn[btnIndex].children[1].innerHTML),
                btnAdd=btn[btnIndex].children[2],
                btnMin=btn[btnIndex].children[0];

            btnShowHide(countNumText,btn[btnIndex], false);

            var iTimeout,iInterval, originalNum,
                beforeRemoveDish=false,
                beforeAddDish=false,
                needRemoveNotify=false; //是否需要删除提醒

            btnAdd.addEventListener(_movestartEvt,function(){

                var _self = this;
                originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
                countNumText =  originalNum +1;
                var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');

                if (countNumText == 1) {
                    if (shopInfo) {
                        _self.parentNode.children[1].innerHTML = 0;
                        beforeAddDish = true;
                        return;
                    } else {
                        _self.parentNode.children[1].innerHTML = 1;
                        btnShowHide(1, _self.parentNode);
                    }
                } else {
                    _self.parentNode.children[1].innerHTML = countNumText;
                    btnShowHide(countNumText,_self.parentNode);
                    iTimeout = setTimeout(function(){
                        // console.log(_self);
                        iInterval = setInterval(function(){
                            countNumText++;
                            _self.parentNode.children[1].innerHTML = countNumText;

                            // 变化打数字
                            _removeClass(_self.parentNode.children[3],'fake');
                            _self.parentNode.children[3].innerHTML = countNumText
                        },100)
                    },1000)
                }
            })

            btnAdd.addEventListener(_moveendEvt,function(){
                clearTimeout(iTimeout);
                clearInterval(iInterval);
                hideBigFont();

                var _self = this;
                var countNumText =  parseInt(_self.parentNode.children[1].innerHTML, 10);
                var dishid = _self.parentNode.parentNode.getAttribute('dishid');
                var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');

                if (beforeAddDish) {

                    setTimeout(function(){
                        MDialog.confirm(
                            '', shopInfo, null,
                            '确定', function(){

                                _self.parentNode.children[1].innerHTML = 1;
                                btnShowHide(1, _self.parentNode);
                                ajaxDishReset(dishid, 1, function(){}, function() {

                                                _self.parentNode.children[1].innerHTML = originalNum;
                                                btnShowHide(originalNum, _self.parentNode);
                                                });

                        }, null,
                            '取消', function(){
                            }, null,
                            null, true, true
                        );
                    }, 500);

                    beforeAddDish = false;
                } else {
                    ajaxDishReset(dishid, countNumText, function(){}, function() {

                                    _self.parentNode.children[1].innerHTML = originalNum;
                                    btnShowHide(originalNum, _self.parentNode);
                                    });
                }

            })

            btnMin.addEventListener(_movestartEvt,function(){

                var _self = this;
                originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
                countNumText =  originalNum -1;


                if(countNumText <= 0 ){
                    _self.parentNode.children[1].innerHTML = 1;
                    beforeRemoveDish = true;
                    return;
                }else{
                    _self.parentNode.children[1].innerHTML = countNumText;
                    iTimeout = setTimeout(function(){

                        iInterval = setInterval(function(){
                                countNumText--;
                                if(countNumText<=0){
                                    clearInterval(iInterval);
                                    _self.parentNode.children[1].innerHTML = 1;
                                    beforeRemoveDish = true;
                                    return;
                                } else {
                                    _self.parentNode.children[1].innerHTML = countNumText;
                                    btnShowHide(countNumText,_self.parentNode);
                                }

                                // 字体放大显示
                                _removeClass(_self.parentNode.children[3],'fake');
                                _self.parentNode.children[3].innerHTML = countNumText
                            },100)
                        },1000)
                    }
            })

            btnMin.addEventListener(_moveendEvt,function(){
                clearTimeout(iTimeout);
                clearInterval(iInterval);
                hideBigFont();

                var _self = this;
                var countNumText =  parseInt(_self.parentNode.children[1].innerHTML, 10);
                var dishid = _self.parentNode.parentNode.getAttribute('dishid');
                var dName = _self.parentNode.parentNode.getAttribute('dName');

                if (beforeRemoveDish) {
                    if (needRemoveNotify) {
                        setTimeout(function(){
                            MDialog.confirm(
                                '', '是否删除'+dName+'？', null,
                                '确定', function(){

                                    _self.parentNode.children[1].innerHTML = 0;
                                    btnShowHide(0, _self.parentNode);
                                    ajaxDishRemove(dishid, function(){}, function() {

                                                        _self.parentNode.children[1].innerHTML = originalNum;
                                                        btnShowHide(originalNum, _self.parentNode);
                                                });
                                }, null,
                                '取消', function(){
                                    _self.parentNode.children[1].innerHTML = originalNum;
                                    btnShowHide(originalNum, _self.parentNode);
                                }, null,
                                null, true, true
                            );
                        }, 500);
                        beforeRemoveDish = false;
                    } else {
                        _self.parentNode.children[1].innerHTML = 0;
                        btnShowHide(0, _self.parentNode);
                        ajaxDishRemove(dishid, function(){}, function() {

                                            _self.parentNode.children[1].innerHTML = originalNum;
                                            btnShowHide(originalNum, _self.parentNode);
                                    });
                        beforeRemoveDish = false;
                    }
                } else {
                    ajaxDishReset(dishid, countNumText, function(){}, function() {

                                    _self.parentNode.children[1].innerHTML = originalNum;
                                    btnShowHide(originalNum, _self.parentNode);
                                  });

                }
            }) // btnMin.addEventListener
        } // for

        function ajaxDishReset(dishid, o2uNum, successCallback, errorCallback) {

            var params = {
                'dishid' : dishid,
                'o2uNum' : o2uNum,
            };

            _doAjax('/caidan.php?action=iAdd', 'POST', params, function(ret) {
                    if (ret['code'] != 0) {
                        errorCallback();
                        alert(ret['message']);
                        return;
                    } else {
                        successCallback();
                    }
            });
        } // ajaxDishReset

        function ajaxDishRemove(dishid, successCallback, errorCallback) {

            var params = {
                'dishid' : dishid,
                'qrcode' : qrcode,
                'code' : code,
                'ticket' : ticket,
            };

            _doAjax('/caidan.php?action=iRemove', 'POST', params, function(ret) {
                if (ret['code'] != 0) {

                    errorCallback();
                    alert(ret['message']);
                    return;
                } else {
                    successCallback();
                }
            });
        } // ajaxDishRemove
    } // doSelectBtn


    function hideBigFont(){
        var _arr = _qAll(".fixBig");
        _forEach(_arr,function(ele,idx,_arr){
            _addClass(ele,'fake');
        })
    }

    function btnShowHide(num,btns, isCountDish){

        if (isCountDish !== false) {
            countDish();
        }

        if (num <= 0) {
            btns.children[0].style.display ="none";
            btns.children[1].style.display ="none";
        }else{
            btns.children[0].style.display ="inline-block";
            btns.children[1].style.display ="inline-block";
        };
    }

    function countDish(){

        var countTotle = 0,countdish;
        var dishNum = _qAll("#diancan section article dl .btn i");
        _forEach(dishNum,function(ele,idx,dishNum){
            countdish = parseInt(ele.innerHTML);
            if(countdish>0){
                countTotle++;
            }
        });

        if(countTotle != 0){
            _q("#diancan nav dl dd.active span").innerHTML = countTotle;
            _q("#diancan nav dl dd.active span").style.display='block';
        }else{
            _q("#diancan nav dl dd.active span").style.display='none';
        }
    }


var
	_env = (function(){ var _ua = navigator.userAgent, _m = null, _formatV = function(vstr, vdiv){ var f = vstr.split(vdiv); f = f.shift()+'.'+f.join(''); return f*1; }, _rtn = { ua: _ua, version: null, ios: false, android: false, windows: false, blackberry: false, meizu: false, weixin: false, wVersion: null, qq: false, qVersion: null, touchSupport: ('createTouch' in document), hashSupport: !!('onhashchange' in window) }; _m = _ua.match(/MicroMessenger\/([\.0-9]+)/); if ( _m != null ){ _rtn.weixin = true; _rtn.wVersion = _formatV(_m[1], '.'); }_m = _ua.match(/QQ\/([\d\.]+)$/); if ( _m != null ){ _rtn.qq = true; _rtn.qVersion = _formatV(_m[1], '.'); } _m = _ua.match(/Android(\s|\/)([\.0-9]+)/); if ( _m != null ){ _rtn.android = true; _rtn.version = _formatV(_m[2], '.'); _rtn.meizu = /M030|M031|M032|MEIZU/.test(_ua); return _rtn; } _m = _ua.match(/i(Pod|Pad|Phone)\;.*\sOS\s([\_0-9]+)/); if ( _m != null ){ _rtn.ios = true; _rtn.version = _formatV(_m[2], '_'); return _rtn; } _m = _ua.match(/Windows\sPhone\sOS\s([\.0-9]+)/); if ( _m != null ){ _rtn.windows = true; _rtn.version = _formatV(_m[1], '.'); return _rtn; } var bb = { a: _ua.match(/\(BB1\d+\;\s.*\sVersion\/([\.0-9]+)\s/), b: _ua.match(/\(BlackBerry\;\s.*\sVersion\/([\.0-9]+)\s/), c: _ua.match(/^BlackBerry\d+\/([\.0-9]+)\s/), d: _ua.match(/\(PlayBook\;\s.*\sVersion\/([\.0-9]+)\s/) }; for (var k in bb){ if (bb[k] != null){ _m = bb[k]; _rtn.blackberry = true; _rtn.version = _formatV(_m[1], '.'); return _rtn; } } return _rtn; }()),
	_ua = _env.ua,
	_touchSupport = _env.ios || _env.android || _env.touchSupport,
	_hashSupport = _env.hashSupport,
	_isIOS = _env.ios,
	_isOldIOS = _env.ios && (_env.version<4.5),
	_isAndroid = _env.android,
	_isMeizu = _env.meizu,
	_isOldAndroid22 = _env.android && (_env.version<2.3),
	_isOldAndroid23 = _env.android && (_env.version<2.4),
	_clkEvtType = _touchSupport?'touchstart':'click',
	_movestartEvt = _touchSupport?'touchstart':'mousedown',
	_moveEvt = _touchSupport?'touchmove':'mousemove',
	_moveendEvt = _touchSupport?'touchend':'mouseup',
	_vendor = (/webkit/i).test(navigator.appVersion) ? "webkit": (/firefox/i).test(navigator.userAgent) ? "Moz": "opera" in window ? "O": (/MSIE/i).test(navigator.userAgent) ? "ms": "",
	_has3d = "WebKitCSSMatrix" in window && "m11" in new WebKitCSSMatrix(),
	_trnOpen = "translate" + (_has3d ? "3d(": "("),
	_trnClose = _has3d ? ",0)": ")",
	_needHistory = ( _isIOS && !!(window.history && window.history.pushState) ),
	_appCache = window.applicationCache,

	
	/**
	 * 查找单个元素
	 */
	_q = function(s, context){if (context && typeof context === 'string'){ try{context = _q(context);}catch(ex){console.log(ex);return;} } return (context||document).querySelector(s);},
	/**
	 * 查找元素集合
	 */
	_qAll = function(s, context){if (context && typeof context === 'string'){ try{context = _q(context);}catch(ex){console.log(ex);return;} } return (context||document).querySelectorAll(s);},
	/**
	 * 合并元素查找结果
	 */
	_qConcat = function(){ 		var i=0, leng = arguments.length, arr=[]; 		for (;i<leng;i++){ 			var arg = arguments[i]; 			if (typeof arg === 'string') 				arg = _qAll(arg);			else if ('nodeType' in arg && arg.nodeType === 1)				arg = [arg];			_forEach(arg, function(aitem){				arr.push(aitem);			});		} 		return arr; 	},
	
	
	/**
	 * 字符串trim
	 */
	_trim = function(str){return str.replace(/(^\s+|\s+$)/g, '');},
	
	/**
	 * 遍历
	 */
	_forEach = function(arr, callback) { if (typeof arr === 'string'){ try{arr = _qAll(arr);}catch(ex){console.log(ex);return;} } Array.prototype.forEach.call(arr, callback); },
	/**
	 * 显示元素
	 */
	_show = function() { var i=0, lng=arguments.length, ele; for (;i<lng;i++){ ele = arguments[i]; if (typeof ele==='string'){try{ele = _q(ele);}catch(ex){console.log(ex);return;} } if (ele.nodeType != undefined && ele.nodeType == 1){ele.style.display = ''; ele.removeAttribute('hidden'); }else if (ele.hasOwnProperty('length')){ try{ var arr=[]; _forEach(ele, function(a,b,c){arr.push(a);}); _show.apply(null, arr); }catch(ex){} } } },
		
	/**
	 * 注册页面结构加载后的回调 改进的onload
	 */
	_onPageLoaded = function(callback) {window.addEventListener('DOMContentLoaded',callback);},
	
	/**
	 * 隐藏软键盘(目前对android无效)
	 */
	_hideKeyboard = function(){
		if ('activeElement' in document)
			document.activeElement.blur();
		window.focus();
	},
	/**
	 * 调试输出工具
	 */
	console = window.console || {log: function(){}};

//页面加载时自动执行
_checkOffline();
_html5FixForOldEnv();

//微信@IOS7宽度错误 且_env.weixin第一次进入不正确
if (/iPad/.test(_ua) && _env.ios && _env.version >= 7){
	_onPageLoaded(function(){
		_q('body').style.width = window.innerWidth + 'px';
		
		window.addEventListener('orientationchange', function(e){
			_q('body').style.width = window.innerWidth + 'px';
		}, false);
	});
}
if (location.href.indexOf('qq.com')>-1){ window.onerror = function(){return true;}; }








